package ihis.tms.server.redmine.db;

import ihis.model.GeneralFilter;
import ihis.model.IHISConstants;
import ihis.model.Member;
import ihis.model.Performance;
import ihis.model.PredictedCurve;
import ihis.model.Project;
import ihis.model.Schedule;
import ihis.model.Task;
import ihis.model.Team;
import ihis.model.exception.InvalidFilterException;
import ihis.tms.server.redmine.model.IDNameMap;
import ihis.tms.server.redmine.model.Issue;
import ihis.tms.server.redmine.model.TaskFilter;
import ihis.tms.server.redmine.model.User;

import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import com.ibatis.sqlmap.client.SqlMapClient;

public class TMSDatabase {


	public static Vector<ihis.model.Task> getTasks(ihis.model.TaskFilter oldFilter) throws InvalidFilterException, SQLException
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		Vector<ihis.model.Task> result = new Vector<ihis.model.Task>();
		List<Issue> searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		switch(filter.getTaskType())
		{
			case IHISConstants.TASK_LIST_NONE:
				searchResult = sqlMap.queryForList("GetIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.TASK_TODO));
					}
				break;
			case IHISConstants.TASK_LIST_IN_PROGRESS:
				if(filter.getOwnerType() != IHISConstants.OWNERTYPE_PERSON && filter.getOwnerType() != IHISConstants.OWNERTYPE_TEAM)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have OwnerType");
				if(filter.getStartDate() == null)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have StartDate");
				filter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
				filter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				searchResult = sqlMap.queryForList("GetInProgressIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.TASK_TODO));
					}
				break;
			case IHISConstants.TASK_LIST_COMPLETED:
				if(filter.getOwnerType() != IHISConstants.OWNERTYPE_PERSON && filter.getOwnerType() != IHISConstants.OWNERTYPE_TEAM)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have OwnerType");
				if(filter.getStartDate() == null)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have StartDate");
				filter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
				filter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				searchResult = sqlMap.queryForList("GetCompletedIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.TASK_TODO));
					}
				break;
			case IHISConstants.TASK_LIST_DELAYED:
				if(filter.getStartDate() == null)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have StartDate");
				filter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), true));
				filter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				searchResult = sqlMap.queryForList("GetDelayedIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.RISK_DELAYED));
					}
				break;
			case IHISConstants.TASK_LIST_PLANNED:
				if(filter.getOwnerType() != IHISConstants.OWNERTYPE_PERSON && filter.getOwnerType() != IHISConstants.OWNERTYPE_TEAM)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have OwnerType");
				if(filter.getStartDate() == null)
					throw new InvalidFilterException("Filter for \"IN_PROGRESS\" Task List should have StartDate");
				filter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
				filter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				GeneralFilter.generateNextDate(filter, filter.getPeriodType());
				searchResult = sqlMap.queryForList("GetInNextIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.TASK_TODO));
					}
				break;
			case IHISConstants.TASK_LIST_RISK:
				filter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), IHISConstants.TIME_UNIT_WEEKLY, true));
				filter.setStartDate(new Date(System.currentTimeMillis()));
				searchResult = sqlMap.queryForList("GetRiskyIssues", filter.GetParameter());
				if(searchResult != null)
					for(int i=0; i<searchResult.size(); i++)
					{
						result.add(searchResult.get(i).ConvertToTask(IHISConstants.RISK_POTENTIAL));
					}
				break;
		}
		return result;
	}
	
	public static Vector<ihis.model.Member> getMembers(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		Vector<ihis.model.Member> result = new Vector<ihis.model.Member>();
		List<User> searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {

			searchResult = sqlMap.queryForList("getUsers", filter.GetParameter());
			if(searchResult != null)
				for(int i=0; i<searchResult.size(); i++)
				{
					result.add(new Member(searchResult.get(i).getLogin(), searchResult.get(i).getFirstname(), searchResult.get(i).getLastname()));
				}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	public static Vector<ihis.model.Member> getUsers(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		Vector<ihis.model.Member> result = new Vector<ihis.model.Member>();
		List<User> searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {

			searchResult = sqlMap.queryForList("getUsers", filter.GetParameter());
			if(searchResult != null)
				for(int i=0; i<searchResult.size(); i++)
				{
					result.add(new Member(searchResult.get(i).getLogin(), searchResult.get(i).getFirstname(), searchResult.get(i).getLastname()));
				}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
	
	public static Vector<Project> getProjects()
	{
		Vector<Project> result = new Vector<Project>();
		List<IDNameMap> searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {

			searchResult = sqlMap.queryForList("getProjects");
			if(searchResult != null)
				for(int i=0; i<searchResult.size(); i++)
				{
					result.add(new Project(searchResult.get(i).getId()+"", searchResult.get(i).getName()));
				}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
	
	public static Vector<Team> getTeams()
	{
		Vector<Team> result = new Vector<Team>();
		List<IDNameMap> searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			searchResult = sqlMap.queryForList("getCategories");
			if(searchResult != null)
				for(int i=0; i<searchResult.size(); i++)
				{
					result.add(new Team(searchResult.get(i).getId()+"", searchResult.get(i).getName()));
				}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
	
	public static String getTeamName(int id)
	{
		String result = "";
		IDNameMap searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			searchResult = (IDNameMap) sqlMap.queryForObject("getCategoryByID", id);
			if(searchResult != null)
			{
				result = searchResult.getName();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	
	public static String getUserName(String id)
	{
		String result = "";
		User searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			searchResult = (User) sqlMap.queryForObject("getUserByLogin", id);
			if(searchResult != null)
			{
				result = searchResult.getLastname() + " " + searchResult.getFirstname();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	public static String getProjectName(int id)
	{
		String result = "";
		IDNameMap searchResult;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			searchResult = (IDNameMap) sqlMap.queryForObject("getProjectByID", id);
			if(searchResult != null)
			{
				result = searchResult.getName();
			}
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	public static Vector<Schedule> getPersonalSchedules(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<Schedule> result = new Vector<Schedule>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<User> users;
		List<IDNameMap> projects;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// 개인별 schedule list를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)
		users = (List<User>)sqlMap.queryForList("getUsers", new HashMap());
		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		if(users != null && projects != null)
		{
			for(int uid=0; uid<users.size(); uid++)
			{
				newfilter.setUserId(users.get(uid).getLogin());
				for(int pid=0; pid<projects.size(); pid++)
				{
					newfilter.setProjectId(projects.get(pid).getId()+"");
					newfilter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
					
					Schedule schedule = new Schedule();
					schedule.setOwnerId(users.get(uid).getLogin());
					schedule.setOwnerType(IHISConstants.OWNERTYPE_PERSON);
					schedule.setProjectId(projects.get(pid).getId()+"");
	
					schedule.setPeriodType(filter.getPeriodType());
					schedule.setReportDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
					
					newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
					schedule.setInProgressCnt(getInProgressCount(newfilter));
					schedule.setCompletedCnt(getCompletedIssuesCount(newfilter));
					
					newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), true));
					schedule.setDelayedCnt(getDelayedIssuesCount(newfilter));
					GeneralFilter.generateNextDate(newfilter,filter.getPeriodType());
//					schedule.setPlannedCnt(getInProgressCount(newfilter));
					schedule.setPlannedCnt(getNextPlanCount(newfilter));					
					if(schedule.isEmpty() == false)
						result.add(schedule);
				}
			}
		}
		return result;
	}
	
	public static Vector<Schedule> getTeamSchedules(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<Schedule> result = new Vector<Schedule>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<IDNameMap> teams;
		List<IDNameMap> projects;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// 개인별 schedule list를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)
		teams = (List<IDNameMap>)sqlMap.queryForList("getCategories");
		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		for(int uid=0; uid<teams.size(); uid++)
		{
			newfilter.setTeamId(teams.get(uid).getId()+"");
			for(int pid=0; pid<projects.size(); pid++)
			{
				newfilter.setProjectId(projects.get(pid).getId()+"");
				newfilter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), true));
				
				Schedule schedule = new Schedule();
				schedule.setOwnerId(teams.get(uid).getId()+"");
				schedule.setOwnerType(IHISConstants.OWNERTYPE_TEAM);
				schedule.setProjectId(projects.get(pid).getId()+"");
				schedule.setTeamId(teams.get(uid).getId()+"");

				schedule.setPeriodType(filter.getPeriodType());
				schedule.setReportDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
				
				schedule.setInProgressCnt(getInProgressCount(newfilter));
				schedule.setCompletedCnt(getCompletedIssuesCount(newfilter));
				schedule.setDelayedCnt(getDelayedIssuesCount(newfilter));
				GeneralFilter.generateNextDate(newfilter,filter.getPeriodType());
//				schedule.setPlannedCnt(getInProgressCount(newfilter));
				schedule.setPlannedCnt(getNextPlanCount(newfilter));				
				if(schedule.isEmpty() == false)
					result.add(schedule);
			}
		}
		return result;
	}
	
	public static Vector<PredictedCurve> getPersonalPredictedCurves(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<PredictedCurve> result = new Vector<PredictedCurve>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<User> users;
		List<IDNameMap> projects;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// 개인, 프로젝트별 추이를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)
		users = (List<User>)sqlMap.queryForList("getUsers", new HashMap());
		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		if(users != null && projects != null)
		{
			for(int uid=0; uid<users.size(); uid++)
			{
				newfilter.setUserId(users.get(uid).getLogin());
				for(int pid=0; pid<projects.size(); pid++)
				{
					newfilter.setProjectId(projects.get(pid).getId()+"");
					newfilter.setEndDate(GeneralFilter.generateToDate(filter.getEndDate(), filter.getPeriodType(), false));
					
					PredictedCurve predictedCurve = new PredictedCurve();
					
					int inProgress = getInProgressCount(newfilter);
					int done = getCompletedIssuesCount(newfilter);
					if(inProgress + done > 0)
					{
						predictedCurve.setOwnerType(IHISConstants.OWNERTYPE_PERSON);
						predictedCurve.setOwnerId(newfilter.getUserId());
						predictedCurve.setTeamId(newfilter.getTeamId());
						predictedCurve.setProjectId(newfilter.getProjectId());
						predictedCurve.setMeasureDate(newfilter.getEndDate());
						predictedCurve.setPeriodType(filter.getPeriodType());
						predictedCurve.setValue((double)done/(double)(inProgress + done));
						result.add(predictedCurve);
					}
				}
			}
		}
		return result;
	}
	
	public static Vector<Performance> getPerformances(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<Performance> result = new Vector<Performance>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<User> users;
		List<IDNameMap> projects;
		List<IDNameMap> teams;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// 개인, 프로젝트별 추이를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)

		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		teams = (List<IDNameMap>) sqlMap.queryForList("getCategories");
		users = (List<User>)sqlMap.queryForList("getUsers", new HashMap());
		if(projects != null && users != null)
		{
			for(int pid=0; pid<projects.size(); pid++)
			{
				newfilter.setProjectId(projects.get(pid).getId()+"");
				for(int tid=0; tid<teams.size(); tid++)
				{
					newfilter.setTeamId(teams.get(tid).getId()+"");

					for(int uid=0; uid<users.size(); uid++)
					{
						newfilter.setUserId(users.get(uid).getLogin());
						newfilter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
						newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), true));
						
						int progress = getInProgressCount(newfilter);
						int completed = getCompletedIssuesCount(newfilter);
						int delayed = getDelayedIssuesCount(newfilter);
						Performance perf = new Performance();
						perf.setOwnerId(newfilter.getUserId());
						perf.setTeamId(newfilter.getTeamId());
						perf.setProjectId(newfilter.getProjectId());
						perf.setReportDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
						perf.setPeriodType(filter.getPeriodType());
						perf.setContribution( progress + completed*2 - delayed);
						perf.setManageability(100-delayed);
						perf.setResponsibility((int)(((float)completed/(completed+progress))*100));
						perf.setAttitude(getAttributePoint(newfilter));
						if(perf.isEmpty() == false)
							result.add(perf);
					}
				}
			}
		}
		return result;
	}
	
	public static Vector<PredictedCurve> getTeamPredictedCurves(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<PredictedCurve> result = new Vector<PredictedCurve>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<IDNameMap> teams;
		List<IDNameMap> projects;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// (팀,프로젝트)별 추이를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)
		teams = (List<IDNameMap>)sqlMap.queryForList("getCategories");
		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		for(int uid=0; uid<teams.size(); uid++)
		{
			newfilter.setTeamId(teams.get(uid).getId()+"");
			for(int pid=0; pid<projects.size(); pid++)
			{
				newfilter.setProjectId(projects.get(pid).getId()+"");
				newfilter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
				newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
				
				PredictedCurve predictedCurve = new PredictedCurve();
				
				int inProgress = getInProgressCount(newfilter);
				int done = getCompletedIssuesCount(newfilter);
				if(inProgress + done > 0)
				{
					predictedCurve.setOwnerType(IHISConstants.OWNERTYPE_TEAM);
					predictedCurve.setOwnerId(newfilter.getUserId());
					predictedCurve.setTeamId(newfilter.getTeamId());
					predictedCurve.setProjectId(newfilter.getProjectId());
					predictedCurve.setMeasureDate(newfilter.getEndDate());
					predictedCurve.setPeriodType(filter.getPeriodType());
					predictedCurve.setValue((double)done/(double)(inProgress + done));
					result.add(predictedCurve);
				}
			}
		}
		return result;
	}

	public static Vector<PredictedCurve> getProjectPredictedCurves(ihis.model.GeneralFilter filter) throws SQLException
	{
		Vector<PredictedCurve> result = new Vector<PredictedCurve>();
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		List<IDNameMap> projects;
		ihis.model.TaskFilter newfilter = new ihis.model.TaskFilter();
		
		// Project 추이를 얻어온다. 전체 인원을 프로젝트 별 정보 진행 count정보 (팀은 무관)
		projects = (List<IDNameMap>) sqlMap.queryForList("getProjects");
		for(int pid=0; pid<projects.size(); pid++)
		{
			newfilter.setProjectId(projects.get(pid).getId()+"");
			newfilter.setStartDate(GeneralFilter.generateFromDate(filter.getStartDate(), filter.getPeriodType()));
			newfilter.setEndDate(GeneralFilter.generateToDate(filter.getStartDate(), filter.getPeriodType(), false));
			
			PredictedCurve predictedCurve = new PredictedCurve();
			
			int inProgress = getInProgressCount(newfilter);
			int done = getCompletedIssuesCount(newfilter);
			if(inProgress + done > 0)
			{
				predictedCurve.setOwnerType(IHISConstants.OWNERTYPE_PROJECT);
				predictedCurve.setOwnerId(newfilter.getUserId());
				predictedCurve.setTeamId(newfilter.getTeamId());
				predictedCurve.setProjectId(newfilter.getProjectId());
				predictedCurve.setMeasureDate(newfilter.getEndDate());
				predictedCurve.setPeriodType(filter.getPeriodType());
				predictedCurve.setValue((double)done/(double)(inProgress + done));
				result.add(predictedCurve);
			}
		}
		return result;
	}


	public static Vector<Task> getRisks() throws SQLException, InvalidFilterException
	{
		ihis.model.TaskFilter filter = new ihis.model.TaskFilter();
		filter.setTaskType(IHISConstants.TASK_LIST_RISK);
		return getTasks(filter);
	}
	
	public static int getInProgressCount(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetInProgressIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	public static int getNextPlanCount(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetInNextIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}	
	
	public static int getCompletedIssuesCount(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetCompletedIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
	
	public static int getDelayedIssuesCount(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetDelayedIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
	
	public static int getManagerabilityPoint(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetDelayedIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}

	public static int getAttributePoint(ihis.model.TaskFilter oldFilter)
	{
		TaskFilter filter = new TaskFilter(oldFilter);
		int result = 0;
		SqlMapClient sqlMap = SqlMapClientManager.GetSqlMapClient();
		try {
			result = (Integer)sqlMap.queryForObject("GetAttributeUpdatePoint", filter.GetParameter());
			result -= (Integer)sqlMap.queryForObject("GetDelayedIssuesCount", filter.GetParameter());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		return result;
	}
}
